from tool.vector import Vector

# 默认时从小到达
def sort_enemies_by_distance(player_pot:Vector, enemies:[Vector],ascending:bool=True):
    # 计算每个敌人到玩家的距离
    enemies_with_distance = [(enemy,Vector.distance(player_pot,enemy)) for enemy in enemies]

    # 按距离从大到小排序
    sorted_enemies = sorted(enemies_with_distance, key=lambda x: x[1],  reverse=not ascending)

    # 返回排序后的敌人坐标
    return [enemy for enemy, distance in sorted_enemies]


# 示例
player = Vector(0, 0)
enemies = [Vector(1, 2), Vector(3, 4),Vector (0, 5), Vector(2, 1)]
sorted_enemies = sort_enemies_by_distance(player, enemies)
# print(sorted_enemies[2])


